package com.example.grape_effect.interpolator

import com.lammy.grapeeffect.interpolator.LYInterpolator

// 匀速变速运动的插值器
class UniformAccelerationInterpolator: LYInterpolator {
    var start:Float = 0.0f
    // 初速度
    var v:Float = 0.0f
    // 加速度
    var a:Double = 0.0
    constructor( start:Float, v:Float,  a:Double) {
        this.start = start
        this.v = v
        this.a = a
    }
    // 根据初速度、起始点和终点，确定加速度
    constructor(duration:Long, start: Float, end:Float, v:Float) {
        val d = end - start
        a = 2 *(d - v * duration).toDouble() / (duration * duration)
        this.v = v
        this.start = start
    }
    override fun getValue(time: Long):Float {
        return (start + v * time + (a * time * time)/2).toFloat()
    }
}